package com.inspect.log;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

public class LogSingleton {
	private static Properties prop = new Properties();
	private static LogSingleton instance = null;
	private static Logger logger = null;
	public static boolean init_mark = false;

	private LogSingleton() {

	}

	public static synchronized Logger get_logger(Class cl) {
		if (instance == null) {
			instance = new LogSingleton();
			if (logger == null) {
				logger = Logger.getLogger(cl);
			}
			instance.init();
			return logger;
		} else {
			if (logger == null) {
				logger = Logger.getLogger(cl);
			}
			return logger;
		}
	}

	/* initialize the logger's variables */
	public synchronized void init() {
		if (init_mark == true) {
			return;
		} else {
			try {
				prop.load(new InputStreamReader(
						LogSingleton.class.getClassLoader().getResourceAsStream("log4j.properties")));
				PropertyConfigurator.configure(prop);
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
			init_mark = true;
			return;
		}

	}

}